

#include "list.c"

int compare_int(void* a, void* o)
{
    return *(int*)a - *(int*)o;
}

void free_int(void* a)
{
}

int match_int(void* a, void* q)
{
    printf("a: %d, %d\n", *(int*)a, *(int*)q);
    return *(int*)a == *(int*)q;
}

int print_int(void* a, void* arg)
{
    printf("%d ", *(int*)a);
    return 0;
}

int main(int argc, char const* argv[])
{
    SimpleSortList list;
    list.first = NULL;
    list.compare = compare_int;
    list.free = free_int;
    list.match = match_int;

    int vals[] = { 3, 1, 4, 66, 33, 129, 3 };
    for (int i = 0; i < sizeof(vals) / sizeof(int); i++) {
        insert(&list, &vals[i]);
        printf("insert: %d %d\n", i, vals[i]);
        foreach_list(&list, print_int, NULL);
        printf("\n");
    }
    int q = 3;
    int* res = find_val(&list, &q);

    printf("res; %p\n", res);
    if (res)
        printf("find res: %d\n", *res);

    SimpleListNode* node = find(&list, &q);
    delete (&list, node);
    res = find_val(&list, &q);

    printf("res; %p\n", res);
    if (res)
        printf("find res: %d\n", *res);

    node = find(&list, &q);
    printf("dddd: %p\n", node);
    int iva = 5;
    insert_at(&list, node, &iva);
    foreach_list(&list, print_int, NULL);
    printf("\n");
}
